//
//  SpecialListVC.m
//  ImGuider
//
//  Created by 李陆涛 on 2017/12/26.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "SpecialListVC.h"
#import "SpecialNodeCCell.h"
#import "SpecialDetailVC.h"
#import "SpecailAudioHeaderView.h"

@interface SpecialListVC () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
//@property (weak, nonatomic) IBOutlet SpecailAudioHeaderView *headView;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (nonatomic, strong) NSArray *dataSource;

//@property (nonatomic) NSInteger sortType;// 0 默认，1最新

@end

@implementation SpecialListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = MYLocalizedString(@"HOME_THEME", nil);
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"SpecialNodeCCell" bundle:nil] forCellWithReuseIdentifier:@"SpecialNodeCCell"];
    [self setupData];
    
    self.view.backgroundColor = kBGColor;
    self.collectionView.backgroundColor = kBGColor;
//    self.headView.sortType = self.sortType;
}

- (void)setupData {
    
    [ActivityIndicatorView showHUDAddedTo:self.view];
//    if (!self.city) {
//
//        [NetAPIManager getMoreAlbumsWithBlock:^(NSArray<LineModel *> *albumsArray, NSError *error) {
//
//            [ActivityIndicatorView hideHUDAddedTo:self.view];
//            self.dataSource = albumsArray;
//            [self.collectionView reloadData];
//        }];
//    }
    
    [NetAPIManager getMoreAlbumsWithBlock:^(NSArray<LineModel *> *albumsArray, NSError *error) {
        
        [ActivityIndicatorView hideHUDAddedTo:self.view];
        self.dataSource = albumsArray;
        [self.collectionView reloadData];
    }];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LineModel *model = self.dataSource[indexPath.row];
    SpecialNodeCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SpecialNodeCCell" forIndexPath:indexPath];
    cell.model = model;
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LineModel *model = self.dataSource[indexPath.row];
    
    SpecialDetailVC * vc = [[SpecialDetailVC alloc] init];
    vc.specialid = model.lineid;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat width = kScreenWidth - 32;
    CGFloat height = width * 9 / 16;
    
    return CGSizeMake(width, height);
}

@end

